package com.koron.car.web.applycar.bean.vo;

import cn.hutool.core.date.DateUtil;
import com.koron.car.web.applycar.bean.entity.CarApply;
import com.koron.car.web.applycar.bean.entity.CarEntourage;
import com.koron.car.web.applycar.bean.entity.DriverRecord;
import com.koron.car.web.applycar.bean.entity.DriverSchedule;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author twcao
 * @title: CarApplyVO
 * @projectName GDH_EAM_V2
 * @description: 车辆申请实体（含详情）
 * @date 2022/3/914:16
 */
@Data
@ApiModel("用车申请")
public class CarApplyVO extends CarApply {

    @ApiModelProperty("随行人员")
    private List<CarEntourage> entourages = new ArrayList<>();

    @ApiModelProperty("调度信息")
    private DriverSchedule schedule;

    @ApiModelProperty("是否领导")
    private String leader;

    @ApiModelProperty("领导id，多个之间，逗号分隔")
    private String leaderId;

    @ApiModelProperty("领导名字，多个之间，逗号分隔")
    private String leaderName;

    @ApiModelProperty(value = "当前节点名称")
    private String currNodeName;

    @ApiModelProperty(value = "当前节点处理人")
    private String currNodeUser;

    @ApiModelProperty(value = "当前节点处理人账号")
    private String currNodeUserId;

    @ApiModelProperty("用车人，随行人员，多个之间，逗号分隔")
    private String entourage;

    @ApiModelProperty("行驶信息")
    private String driverLine;

    @ApiModelProperty("用车时间")
    private String driverTime;

    @ApiModelProperty("调度司机")
    private String scheduleDriver;

    @ApiModelProperty("调度车辆")
    private String scheduleCar;

    @ApiModelProperty("是否为基层用车，保存后由后端判断设值")
    private String primary;

    @ApiModelProperty("用车类型，用于工作流判断，区别于字段：applyCarType")
    private String usingCarType;

    @ApiModelProperty("行驶中的记录，有了记录，但是没有填写起始里程或结束里程")
    private DriverRecord driverRecord;

    @ApiModelProperty("公司领导集合")
    private List<String> leaderArr;

    public String getEntourage() {
        return StringUtils.join(entourages.stream().map(CarEntourage::getUserName).collect(Collectors.toList()), ",");
    }

    public String getDriverLine() {
        return this.getOrigin() + "-" + this.getDestination();
    }

    public String getDriverTime() {
        return DateUtil.format(this.getStartTime(), "yyyy-MM-dd HH:mm") + " 至 " + DateUtil.format(this.getEndTime(), "yyyy-MM-dd HH:mm");
    }

    public String getScheduleDriver() {
        return schedule == null ? "" : schedule.getDriverName();
    }

    public String getScheduleCar() {
        return schedule == null ? "" : schedule.getLicPlateNum();
    }
}
